/**
 * Created by shenbo on 2017/7/31.
 */
import multiChannel from '../../../../api/config/channel/multi-channel'
import * as globalTypes from '../../../../mutation-types'

 /* 快捷回复设置 start */
  /**
   * 查询所有快捷回复分类
   * @param data.moduleType  webchat/email 模块类型
   * @returns {*}
   */
export const queryAllTitle = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryAllTitle(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 快捷回复批量删除 start */
/**
 * @param data.moduleType  webchat/email 模块类型
 * @returns {*}
 */
export const queryDetele = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryDetele(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
   * 根据分类名称查询下面的快捷回复语
   * @param data
   * @returns {*}
   */
export const queryQuickReplyByTitle = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryQuickReplyByTitle(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
   * 根据输入内容查询所有快捷回复语
   * @param data
   * @returns {*}
   */
export const queryQuickReplyByContent = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryQuickReplyByContent(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

  /**
   * 查询一条快捷回复语的详细信息
   * @param data
   * @returns {*}
   */
export const queryQuickReplyById = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryQuickReplyById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 删除一条快捷回复语
   * @param data
   * @returns {*}
   */
export const deleteQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.deleteQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 修改快捷回复
   * @param data
   * @returns {*}
   */
export const updateQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.updateQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 添加快捷回复
   * @param data
   * @returns {*}
   */
export const addQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.addQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
 * 自定义快捷回复导入Excel文件
 * @param data
 * @returns {*}
 */
export const quickReplyAgentImport = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.quickReplyAgentImport(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 公共快捷回复导入上传的Excel文件
   * @param data
   * @returns {*}
   */
export const quickReplyImportNew = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.quickReplyImportNew(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 导出自定义快捷回复或公共快捷回复
 * @param data
 * @returns {*}
 */
export const exportQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.exportQuickReply(data)
    .then(response => {
      if (response.Succeed) {
        commit(globalTypes.SET_FILEDOWNLOAD, { path: response.path, isSession: true })
      } else {
      }
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
   * 邮件模块确定导入上传的Excel文件
   * @param data
   * @returns {*}
   */
export const quickReplyImportMail = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.quickReplyImport(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
 /* 快捷回复设置 end */

 /* 满意度配置 start */
  /**
   * 获取满意度配置
   * @param data {}
   * @param data.type webchatCSR
   * @returns {*}
   */
export const getCSRDic = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.getCSRDic(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 保存满意度配置
   * @param data {}
   * data._id
   * @param data.type webchatCSR
   * data.options [{key: '' index: '' name: '' reason []}]
   * @returns {*}
   */
export const saveCSRDic = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.saveCSRDic(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const queryBlackUser = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryBlackUser(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const deleteBlackUser = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.deleteBlackUser(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const editBlackReason = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.editBlackReason(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const untieBlackUser = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.untieBlackUser(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * IP黑名单列表查询
 * @param data {}
 * @param data.page
 * @param data.limit
*/
export const queryBlackIpRangeList = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryBlackIpRangeList(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 新增IP黑名单
 * @param data {} 
*/
export const addBlackIpRange = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.addBlackIpRange(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 修改IP黑名单
 * @param data {}  
*/
export const editBlackIpRange = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.editBlackIpRange(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除IP黑名单
 * @param data {}
 * @param data._id 
*/
export const deleteBlackIpRangeList = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.deleteBlackIpRangeList(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询被IP黑名单拉黑的会话
 * @param data {}
 * @param data._id 
*/
export const queryBlackIpRangeUser = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryBlackIpRangeUser(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 新增快捷回复类别
 * @param data {}
 * @param data.name
 * @param data.moduleType   'webchat'
 * @param data.sort   0
 * @returns {*}
 */
export const newAddQuickReplyTag = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newAddQuickReplyTag(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新快捷回复类别
 * @param data {}
 * @param data.name
 * @param data.moduleType   'webchat'
 * @param data.sort   0
 * @param data.name   ""
 * @returns {*}
 */
export const newUpdateQuickReplyTag = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newUpdateQuickReplyTag(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询快捷回复分类
 * 列表查询 不传name
 * @param data {}
 * @param data.name           模糊查询
 * @param data.moduleType   'webchat'
 * @param data.content   ""  在线咨询右侧模糊查询
 * @returns {*}
 */
export const newQueryQuickReplyTag = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newQueryQuickReplyTag(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除快捷回复类别
 * @param data {}
 * @param data.ids           类别id数组
 * @param data.moduleType   'webchat'
 * @returns {*}
 */
export const newDeleteQuickReplyTag = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newDeleteQuickReplyTag(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 根据类别查询快捷回复
 * @param data {}
 * @param data.tagParentId           类别id
 * @param data.moduleType   'webchat'
 * @returns {*}
 */
export const newQueryQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newQueryQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询所有类别下的快捷回复
 * @param data {}
 * @param data.tagParentId           类别id
 * @param data.moduleType   'webchat'
 * @returns {*}
 */
export const queryAllQuickReplyNew = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryAllQuickReplyNew(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 新增快捷回复语
 * @param data {}
 * @param data.tagParentId           类别id
 * @param data.moduleType   'webchat'
 * @param data.content   ''     快捷回复内容
 * @param data.quickContent   ''    快捷词
 * @returns {*}
 */
export const newAddQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newAddQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 更新快捷回复
 * @param data {}
 * @param data._id           快捷回复id
 * @param data.content    ''      快捷回复内容
 * @param data.quickContent    ''      快捷词
 * @param data.moduleType   'webchat'
 * @returns {*}
 */
export const newUpdateQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newUpdateQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 删除快捷回复
 * @param data {}
 * @param data._ids           快捷回复ids
 * @param data.content    ''      快捷回复内容
 * @param data.quickContent    ''      快捷词
 * @param data.moduleType   'webchat'
 * @returns {*}
 */
export const newDeleteQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newDeleteQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新公共快捷回复分类排序
 * @param data tags         分类数据数组
 * @returns {*}
 */
export const newBatchUpdateQuickReplyTag = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newBatchUpdateQuickReplyTag(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新公共快捷回复分类排序
 * @param data replys         回复语数组
 * @returns {*}
 */
export const newBatchUpdateQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newBatchUpdateQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新自定义快捷回复分类排序
 * @param data tags         分类数据数组
 * @returns {*}
 */
export const newBatchUpdateAgentQuickReplyTag = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newBatchUpdateAgentQuickReplyTag(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新公共快捷回复分类排序
 * @param data replys         回复语数组
 * @returns {*}
 */
export const newBatchUpdateAgentQuickReply = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.newBatchUpdateAgentQuickReply(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取在线自定义状态列表
 * @param data
 * @returns {*}
 */
export const queryWebStatusConfig = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryWebStatusConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新在线自定义状态
 * @param data isEnable（状态 '1' 启用 '0' 停用）webStatusId （状态编号）webStatusName （状态名）updateTime（更新时间）
 * @returns {*}
 */
export const saveWebStatusConfig = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.saveWebStatusConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取在线自定义状态
 * @param data
 * @returns {*}
 */
export const queryEnableWebStatus = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryEnableWebStatus(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 增加表单消息
 * @param data
 * @returns {*}
 */
export const addSessionForm = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.addSessionForm(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 修改表单消息
 * @param data
 * @returns {*}
 */
export const editSessionForm = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.editSessionForm(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除表单消息
 * @param data
 * @returns {*}
 */
export const deleteSessionForm = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.deleteSessionForm(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询表单消息列表
 * @param data
 * @returns {*}
 */
export const querySessionForm = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.querySessionForm(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 导入在线标签
 * @param data
 * @param data.batchNo 批次号
 * @param data.batchRemark 批次号说明
 * @param data.fileName  上传的文件id
 * @param data.trueName  上传的文件名
 * @returns {*}
 */
export const importWebchatLabel = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.importCallLabel(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

export const queryWebchatLabelImportTask = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.queryWebchatLabelImportTask(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const delWebchatLabelImportTask = ({commit, state, rootState, dispatch}, data) => {
  return multiChannel.delWebchatLabelImportTask(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
